package com.luobr.backend.exception;

import com.luobr.backend.common.ResponseCode;
import lombok.Getter;

/**
 * 业务异常
 * 自定义一个业务异常，和内置的异常类区分开，便于定制化输出错误信息
 */
@Getter
public class BusinessException extends RuntimeException {

    // 错误码 code
    private final int code;

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(ResponseCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
    }

    // errorCode 里面的 message 为通用错误信息，message 为具体错误信息
    public BusinessException(ResponseCode errorCode,String message) {
        super(message);
        this.code = errorCode.getCode();
    }
}
